package com.alibaba.dingtalk.openapi.newmessage.entity;/*/*/

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;
/**
 *
 * @author 魏荣杰
 * @date 2019/3/21 15:37
 * @since v1.0
 * @version v1.0
 */
@Setter
@Getter
@ToString
public class Msg implements Serializable {
    private static final long serialVersionUID = -8024526146661849210L;

    /**
     * 消息类型
     */
    private String msgType;
    private AbstractMessage msg;

    public Msg(AbstractMessage msg) {
        this.msgType = msg.type();
        this.msg = msg;
    }

    public JSONObject toJsonObject() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msgtype", this.msgType);
        jsonObject.put(msg.type(), this.msg);
        return jsonObject;
    }
}
